package boddaert.philippe.cashGame.io.in;

import java.io.File;
import java.io.IOException;

import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.DOMOutputter;

import boddaert.philippe.cashGame.io.InvalidFormatException;

public class XmlReader {

	public static org.w3c.dom.Document read(File file) throws IOException, InvalidFormatException {
		if (file == null || !file.exists())
			throw new IllegalArgumentException();

		SAXBuilder builder = new SAXBuilder();
		Document xmlDocument;
		try {
			xmlDocument = builder.build(file);
		} catch (JDOMException e) {
			throw new InvalidFormatException(e);
		}

		DOMOutputter outputter = new DOMOutputter();
		try {
			return outputter.output(xmlDocument);
		} catch (JDOMException e) {
			throw new IOException(e.getMessage());
		}
	}

}
